#coding: utf-8
import pymongo

from dbproxy.dbproxy import *
import settings
import MongoOper

from werkzeug.contrib.fixers import LighttpdCGIRootFix
from flask import Flask
from flask_pymongo import PyMongo, DESCENDING
from functools import wraps
import json

import urllib, urllib3

app = settings.app
mongo = settings.mongo

def test12():
    db = mongo
    db_proxy = DBProxy(db=db)

    # 建立questions_collection
    ques = {
        'question_id': '1',
        'question_type': 2,
        'question_title': '你购买过下列哪些品牌的产品',
        'type': 1,
        'question_dim': 'o',
        'polar_type': None,
        'require': 0,
        'rule_id': None,
        'A': '李宁',
        'B': '匡威',
        'C': '安踏',
        'D': '阿迪',
        'E': None,
        'F': None,
        'G': None,
        'H': None,
        'I': None,
        'J': None,
        'company_id': '001'
    }

    db_proxy.insert('questions_collection', ques)

from urllib.parse import urlencode

def test_edit():
    test_data = {'question_id': '1', 'data':{'require': 10}}
    test_data = json.dumps(test_data).encode('utf-8')
    # test_data = urlencode(test_data)
    url = 'http://127.0.0.1:5000/custom/question_edit'
    http = urllib3.PoolManager()
    r = http.request('POST', url, body = test_data, headers={'Content-Type': 'application/json'})
    print(r.status)
    print(r.data)

if __name__ == '__main__':
    test_edit()